//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "Polynomial2DSpline.h"
using namespace Cephei::QL::Experimental::Inflation;
#include <gen/QL/Math/Matrix.h>
#include <gen/QL/Math/Interpolations/Interpolation2D.h>
using namespace Cephei::QL::Math;
using namespace Cephei::QL::Math::Interpolations;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::CPolynomial2DSpline (boost::shared_ptr<QuantLib::Polynomial2DSpline>& childNative, Object^ owner) : CInterpolation2D(CPolynomial2DSpline::typeid)
{
#ifdef HANDLE
	_phPolynomial2DSpline = NULL;
#endif
	_ppPolynomial2DSpline = &childNative;
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppPolynomial2DSpline));
}
Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::CPolynomial2DSpline (QuantLib::Polynomial2DSpline& childNative, Object^ owner) : CInterpolation2D(CPolynomial2DSpline::typeid)
{
#ifdef HANDLE
	_phPolynomial2DSpline = NULL;
#endif
	_ppPolynomial2DSpline = new boost::shared_ptr<QuantLib::Polynomial2DSpline> (&childNative);
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppPolynomial2DSpline));
    _Polynomial2DSplineOwner = owner;
    _Interpolation2DOwner = owner;
}

Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::CPolynomial2DSpline (CPolynomial2DSpline^ copy) : CInterpolation2D(CPolynomial2DSpline::typeid)
{
#ifdef HANDLE
	_phPolynomial2DSpline = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppPolynomial2DSpline = new boost::shared_ptr<QuantLib::Polynomial2DSpline> (copy->GetShared());
        _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppPolynomial2DSpline));
    }
}
Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::CPolynomial2DSpline (System::Type^ t) : CInterpolation2D(CPolynomial2DSpline::typeid)
{
#ifdef HANDLE
	_phPolynomial2DSpline = NULL;
#endif
	if (!t->IsSubclassOf(CPolynomial2DSpline::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::CPolynomial2DSpline (QuantLib::Handle<QuantLib::Polynomial2DSpline>& childNative, Object^ owner)  : CInterpolation2D(CPolynomial2DSpline::typeid)
{
	_phPolynomial2DSpline = &childNative;
	_ppPolynomial2DSpline = &static_cast<boost::shared_ptr<QuantLib::Polynomial2DSpline>>(childNative.currentLink());
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppPolynomial2DSpline));
    _Polynomial2DSplineOwner = owner;
}
Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::CPolynomial2DSpline (QuantLib::Handle<QuantLib::Polynomial2DSpline> childNative)  : CInterpolation2D(CPolynomial2DSpline::typeid)
{
	_phPolynomial2DSpline = &childNative;
	_ppPolynomial2DSpline = &static_cast<boost::shared_ptr<QuantLib::Polynomial2DSpline>>(childNative.currentLink());
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppPolynomial2DSpline));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::CPolynomial2DSpline (QuantLib::Polynomial2DSpline childNative)  : CInterpolation2D(CPolynomial2DSpline::typeid)
{
#ifdef HANDLE
	_phPolynomial2DSpline = NULL;
#endif
	_ppPolynomial2DSpline = new boost::shared_ptr<QuantLib::Polynomial2DSpline> (new QuantLib::Polynomial2DSpline (childNative));
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppPolynomial2DSpline));
}
#endif

Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::~CPolynomial2DSpline ()
{
    if (_ppPolynomial2DSpline != NULL)
    {
	    delete _ppPolynomial2DSpline;
        _ppPolynomial2DSpline = NULL;
    }
}
Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::!CPolynomial2DSpline ()
{
    if (_ppPolynomial2DSpline != NULL)
    {
	    delete _ppPolynomial2DSpline;
    }
}
QuantLib::Polynomial2DSpline& Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::GetReference ()
{
    if (_ppPolynomial2DSpline == NULL) throw gcnew NativeNullException ();
	return **_ppPolynomial2DSpline;
}
boost::shared_ptr<QuantLib::Polynomial2DSpline>& Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::GetShared ()
{
    if (_ppPolynomial2DSpline == NULL) throw gcnew NativeNullException ();
	return *_ppPolynomial2DSpline;
}
QuantLib::Polynomial2DSpline* Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::GetPointer ()
{
    if (_ppPolynomial2DSpline == NULL) throw gcnew NativeNullException ();
	return &**_ppPolynomial2DSpline;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Polynomial2DSpline>& Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::GetHandle ()
{
	if (_phPolynomial2DSpline == NULL)
	{
		_phPolynomial2DSpline = new Handle<QuantLib::Polynomial2DSpline> (*_ppPolynomial2DSpline);
	}
	return *_phPolynomial2DSpline;
}
#endif
bool Cephei::QL::Experimental::Inflation::CPolynomial2DSpline::HasNative () 
{
	return (_ppPolynomial2DSpline != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

